import java.util.Collection;

import javax.jms.*;
import javax.naming.InitialContext;

import org.eticom.jee.entity.Libro;
import org.eticom.jee.sesion.LibroBeanRemote;


public class ClienteMensajeria {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Queue queue;
		QueueConnection cnn;
		QueueSession sess;
		QueueSender sender;
		
		try{
		
			InitialContext context = new InitialContext();		
			queue = (Queue) context.lookup("ColaProcesadorTextos");
			
			QueueConnectionFactory factory = 
					(QueueConnectionFactory) context.lookup("QueueConnectionFactory");
			cnn = factory.createQueueConnection("guest","guest");
			
			sess = cnn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
			
			sender=sess.createSender(queue);
			
			LibroBeanRemote libroBean =
				(LibroBeanRemote) context.lookup("org.eticom.jee.sesion.LibroBeanRemote");

			Collection<Libro> libros = libroBean.getLibrosRemote();
			
			for(Libro libro:libros){
				Thread.sleep(5000);
				sender.send(sess.createTextMessage(libro.getTitulo()));
			}
			
			
			sess.close();
			
			cnn.close();
		
			
			
		
		}catch(Exception e){
			
		
		}
		
		
		

	}

}
